/**
 *  @file  vsLogOutput.h version 1.0 2007-11-20 
 *  @brief Define class LogOutput.
 *  Copyright (c) 2007 by @author <abitfree@gmail.com>
 */

#ifndef __VS_LOGOUTPUT_H__
#define __VS_LOGOUTPUT_H__

#include <string>

namespace vs {
namespace log {

/**
 * @brief The base class of log output.
 *
 * The abstraction of the log output object, the log output can be screen, a file, and so on.
*/
class LogOutput
{
public:
	/// The constructor.
	LogOutput();
	
	/// The pure virtual destructor.
	virtual ~LogOutput() = 0;

	/// Write a log message, it is usually called by the Logger class objects.
	virtual int Write(const char *pszMsg, int nSize, struct tm *pWriteTime);

	/// Flush log messages.
	virtual void Flush();

	//@{
	/// Testing the status of the log out object, to decide whether can write log messages to it.
	bool IsValid() const;
	operator bool () const;
	//@}

protected:
	/**
	 * @brief The Open() method is used to open the log output.
	 *
	 * The log output should be setup before calling this method. The log output can be setup by its constructor,
	 * or by its setter methods. Only after calling this method, messages can be logged to this output.
	 */
	virtual bool Open();
	
	/// Close the log output.
	virtual void Close();

private:
	// Disable copying from another instance.
	LogOutput(const LogOutput &target);
	void operator = (LogOutput &target);

protected:
	/// The status of the log output object.
	bool m_bValid;
};

#define INLINE inline


// implementation for LogOutput
INLINE
LogOutput::LogOutput()
	: m_bValid(false)
{
	m_bValid = Open();
}

INLINE
LogOutput::~LogOutput()
{
	Close();
}

INLINE
int LogOutput::Write(const char *pszMsg, int nSize, struct tm *pWriteTime)
{
	return 0;
}

INLINE
void LogOutput::Flush()
{
}

INLINE
bool LogOutput::IsValid() const
{
	return m_bValid;
}

INLINE
LogOutput::operator bool () const
{
	return m_bValid;
}

INLINE
bool LogOutput::Open()
{
	return true;
}

INLINE
void LogOutput::Close()
{
	m_bValid = false;
}

} // namespace log
} // namespace vs


#endif // __VS_LOGOUTPUT_H__
